const chalk = require('chalk');
const prompts = require('prompts');
const { isStringAndHasLength, hasFilePromiseHandler } = require('../../helper.js');
const { replaceHandler2 } = require('./replaceHandler2.js');



async function i18n2(dealfile) {
    await prompts([
    {
        type: 'text',
        name: 'i18nPath',
        message: `默认执行作用域下的 i18n.json文件\n`
    }])
    replaceHandler2({ fileOrDirString: dealfile, i18nUrl: 'i18n.json' });
}

/**
 * 替换功能
 */
async function replaceInit2() {
    const res =  await prompts([
        {
            type: 'text',
            name: 'dealPackage',
            message: `请输入要替换文件夹路径【以根目录为主（（和src平级））】`
        },
    ])
    
    const hasFile = await hasFilePromiseHandler(res.dealPackage);
    if (hasFile) {
        i18n2(res.dealPackage)
    } else {
        console.log(chalk.red(`没找到您输入的文件夹！`));
    }

}

module.exports = {
    replaceInit2
}